public class Login {
    //自定义异常
    private String userName = "admit";
    private String password = "123456";

    public void LoginInfo(String userName, String password)
            throws UserNameException, PassWordException {
        if (!this.userName.equals(userName)) {
            throw new UserNameException("用户名异常");
        }
        if (!this.password.equals(password)) {
            throw new PassWordException("密码异常");
        }
        System.out.println("登录成功！");
    }

    public static void main(String[] args) {
        Login login = new Login();
        try {
            login.LoginInfo("admit", "123456");
        } catch (UserNameException e) {
            System.out.println("捕捉到了UserNameException...");
            e.printStackTrace();
        } catch (PassWordException e) {
            System.out.println("捕捉到了PassWordException...");
            e.printStackTrace();
        } finally {
            System.out.println("Finally...");
        }
    }
}

